<template>
    <div id="list">
        <!-- 头部刷新区域 -->
        <div class="setdiv">
            <span>退还原因设置</span>
            <el-button class="refreshRight" plain icon="el-icon-refresh" @click="shuaxin">刷新</el-button>
        </div>
        <div id="button">
            <el-button @click="qbdd()" class="anniu" type="primary" size="medium" plain>全部申请</el-button>
            <el-button @click="dfk()" class="anniu" type="primary" size="medium" plain>待处理</el-button>
            <el-button @click="dfh()" class="anniu" type="primary" size="medium" plain>已处理</el-button>
            <el-button @click="yfh()" class="anniu" type="primary" size="medium" plain>已拒绝</el-button>

        </div>
        <el-card>
            <!-- 查询内容区域 -->
            <el-collapse v-model="activeNames">
                <el-collapse-item title="筛选查询" name="1">
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <div id="input1">
                            关键词<el-input class="input" v-model="formInline.search" placeholder="订单号/商品货号"></el-input>
                            收货人<el-input class="input" v-model="formInline.phone" placeholder="用户昵称/手机号"></el-input>
                            申请状态<el-select v-model="formInline.type" class="input" slot="prepend" placeholder="申请状态">
                                <el-option label="待付款" value="待付款"></el-option>
                                <el-option label="已完成" value="已完成"></el-option>
                                <el-option label="已关闭" value="已关闭"></el-option>
                            </el-select>
                        </div>
                    </el-form>
                    <div id="anniu1">
                        <el-button type="info" plain @click="Reset">重置</el-button>
                        <el-button type="info" plain @click="Screening">筛选</el-button>
                    </div>
                </el-collapse-item>
            </el-collapse>
            <!-- 获取数据列表 -->
            <div id="shuju">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>数据列表</span>
                        <!-- 批量删除按钮 -->
                        <el-button style="float: right; padding: 3px 0" type="text" @click="batchDelSure">批量删除</el-button>
                    </div>
                    <!-- 初始化表格区域 -->
                    <div id="card">
                        <el-table :data="tableData" border style="width: 100%" @selection-change="selectCheck">
                            <el-table-column type="selection" width="55">
                            </el-table-column>
                            <el-table-column prop="id" label="序号" width="95">
                            </el-table-column>
                            <el-table-column prop="ordernum" label="订单编号" width="180">
                            </el-table-column>
                            <el-table-column prop="subtime" label="申请时间" width="220">
                            </el-table-column>
                            <el-table-column prop="phone" label="用户账号" width="180">
                            </el-table-column>
                            <el-table-column prop="money" label="金额" width="120">
                            </el-table-column>
                            <el-table-column prop="describe" label="类型" width="120">
                            </el-table-column>
                            <el-table-column prop="type" label="申请状态" width="120">
                            </el-table-column>
                            <el-table-column prop="handletime" label="处理时间" width="220">
                            </el-table-column>
                            <el-table-column label="操作" width="120">
                                <template slot-scope="scope">
                                    <el-button @click="ChecDketails(scope.row)" type="text">
                                        查看订单
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-card>
            </div>
            <!-- 分页区域 -->
            <div id="fenye">
                <div class="block">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :page-sizes="[5, 10, 20, 30]" layout="total, sizes, prev, pager, next, jumper" :total="ReturnData.length" :page-size="eachNum" :current-page.sync="nowPage">
                    </el-pagination>
                </div>
            </div>
            <div></div>
        </el-card>
    </div>
</template>
<script>
// 引用规范时间的方法
import date from "../../components/package";
export default {
    data() {
        return {
            // 当前页
            nowPage: 1,
            // 每页显示五条
            eachNum: 5,
            // 存储初始化数据
            ReturnData: [],
            // 筛选内容区域
            formInline: {
                phone: "",
                type: "",
                search: "",
            },
            // 头部折叠区域
            activeNames: ["1"],
        };
    },
    created() {
        // 初始化数据
        this.getAllRole();
    },
    methods: {
        // 初始化数据
        getAllRole() {
            this.$axios({
                url: "/orders/getReturnOrders",
            }).then((res) => {
                res.data.data.filter((v) => {
                    if (v.subtime) {
                        v.subtime = date.dateFn(v.subtime);
                    }
                    if (v.handletime) {
                        v.handletime = date.dateFn(v.handletime);
                    }
                });

                this.ReturnData = res.data.data;
                console.log(this.ReturnData);
            });
        },
        qbdd() {
            this.$router.push("list");
        },
        dfk() {
            this.$router.push("dfk");
        },
        dfh() {
            this.$router.push("dfh");
        },
        yfh() {
            this.$router.push("yfh");
        },
        ywc() {
            this.$router.push("ywc");
        },
        ygb() {
            this.$router.push("ygb");
        },
        // 刷新事件
        shuaxin() {
            this.$message({
                message: "刷新成功",
                type: "success",
            });
        },
        //监听pagesize改变的事件
        handleSizeChange(newSize) {
            // console.log(newSize);
            this.eachNum = newSize;
            this.getAllRole();
        },
        // 监听页码值的改变的事件
        handleCurrentChange(newPage) {
            this.nowPage = newPage;
            this.getAllRole();
        },
        // 筛选按钮监听事件
        Screening() {
            this.nowPage = 1;
            this.$axios({
                url: "/orders/getsearch",
                params: {
                    phone: this.formInline.phone,
                    search: this.formInline.search,
                    type: this.formInline.type,
                },
            }).then((res) => {
                res.data.data.filter((v) => {
                    if (v.subtime) {
                        v.subtime = date.dateFn(v.subtime);
                    }
                    if (v.handletime) {
                        v.handletime = date.dateFn(v.handletime);
                    }
                });
                console.log(res.data);
                if (res.data.code == 200) {
                    this.ReturnData = res.data.data;
                }
            });
        },
        // 重置
        Reset() {
            this.nowPage = 1;
            this.formInline.phone = "";
            (this.formInline.search = ""),
                (this.formInline.type = ""),
                this.getAllRole();
        },
        // 批量删除
        batchDelSure() {
            this.$confirm("确认删除所选退款信息？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                console.log(this.batchDelFrom);
                let str = "";
                for (let i = 0; i < this.batchDelFrom.length; i++) {
                    if (this.batchDelFrom[i].num) {
                        str = str + `"${this.batchDelFrom[i].name}"` + " ";
                    }
                }
                this.batchDel();
            });
        },
        batchDel() {
            this.$axios({
                url: "/Delinformation",
                method: "post",
                data: this.batchDelFrom,
            }).then((res) => {
                console.log(res);
                if (res.data.data.code == 200) {
                    this.getAllRole();
                    this.$message({
                        message: "删除成功",
                        tyep: "success",
                    });
                } else {
                    this.$message({
                        message: "无法删除",
                        tyep: "warning",
                    });
                }
            });
        },
        selectCheck(selection) {
            this.batchDelFrom = selection;
        },
        // 查看详情按钮监听事件
        ChecDketails() {
            this.$router.push("ChecDketails");
        },
    },
    computed: {
        // 计算表格分页
        tableData() {
            return this.ReturnData.slice(
                (this.nowPage - 1) * this.eachNum,
                this.nowPage * this.eachNum
            );
        },
    },
};
</script>
<style lang="less" scopd>
.el-collapse-item__content {
    margin-top: 30px;
}
#button {
    margin-top: -30px;
    margin-bottom: 10px;
}
.setdiv {
    background-color: #f2f2f2;
    padding: 17.5px 0;
    position: relative;
}
.setdiv > span {
    margin-left: 20px;
}
.refreshRight {
    position: absolute;
    right: 20px;
    top: 8px;
}
.anniu {
    width: 100px;
    height: 40px;
    margin-top: 40px;
    text-align: center;
}
.box_card {
    margin-top: 10px;
}
.input {
    width: 200px;
    margin-left: 20px;
    margin-right: 50px;
}
#anniu1 {
    text-align: center;
    margin-top: 40px;
}
#input1 {
    text-align: center;
}
#card {
    margin-top: 20px;
}
#shuju {
    margin-top: 10px;
}
#fenye {
    margin-top: 10px;
    text-align: center;
}

.el-collapse-item__header {
    padding-left: 18px;
    font-size: 16px;
    height: 56px;
    background-color: rgb(242, 242, 242);
}
</style>
